package com.nutstudio.feitoys.base;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;


import com.nutstudio.feitoys.R;
import com.nutstudio.feitoys.bean.PlaceBean;

import java.util.List;

/**
 * 主界面 图标排列适配器
 * Created by admin on 2016/1/13.
 */
public class CityAdapter extends RecyclerView.Adapter<CityAdapter.ViewHolder> {
    private List<PlaceBean> list;
    private LayoutInflater mInflater;
    public CityAdapter(Context context, List<PlaceBean> list) {
        mInflater = LayoutInflater.from(context);
        this.list = list;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    private OnItemClickListener aOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {

        this.aOnItemClickListener = mOnItemClickListener;
    }

    @Override
    public ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.city_item, parent, false);
        final ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.title = (TextView) view.findViewById(R.id.text);
        viewHolder.itemRoot=(CardView)view.findViewById(R.id.item_root);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (aOnItemClickListener!=null){
                    aOnItemClickListener.onItemClick(view,viewHolder.getLayoutPosition());
                }

            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        PlaceBean bean=list.get(position);
        holder.title.setText(bean.getName());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView title;
        private CardView itemRoot;
        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
